library(habtools)
library(rgl)
options(rgl.printRglwidget = TRUE)

habtools includes a wide range of complexity metrics applicable to 3D meshes.

Before, calculating any metrics, visualize your mesh and make sure that the z orientation is correct, as this may affect some of the calculations.

plot3d(mcap)

Depending on how the mesh was generated (e.g. with the use of a laser scanner), the resolutions (distance between vertices inside the mesh) can vary a lot. This may affect calculations such as fractal dimension. Check the distribution of resolution of your object and if needed, remesh to make the resolution more uniform.

resvec <- Rvcg::vcgMeshres(mcap)[[2]] # vector of resolutions
hist(resvec)

summary(resvec)
#>     Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
#> 0.001307 0.005265 0.007003 0.007831 0.009410 0.043981

In our example, the ‘mcap’ object has very variable distances between vertices. We can solve this issue by remeshing the object with the Rvcg function vgcUniformRemesh(). Here we set the resolution (voxelSize) to the minimum distance between points in the original mesh to ensure we don’t loose details. This choice may be made on a case-to-case basis. Setting multisample to TRUE improves the accuracy of distance field computation, but slows down the calculation so this choice may be defined by computing power and the size of your object. The remeshed object now has a mean resolution of approximately the minimum of ‘resvec’. While there will still be some variation in the obtained distances between vertices, the variation will be much smaller. An alternative option would be to remesh using an external 3D software such as blender.

mcap_uniform <- Rvcg::vcgUniformRemesh(mcap, silent = TRUE, multiSample = TRUE, voxelSize = min(resvec), mergeClost = TRUE)
plot3d(mcap_uniform, col = "grey")